﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using ServBus.ListForm2010.Setup.Utilities;

namespace ServBus.ListForm2010.Setup.Validators
{
    public class PermissionValidator : BaseValidator
    {
        public override string CheckItemText
        {
            get { return Properties.Resources.CheckingPermission; }
        }

        public override string ValidText
        {
            get { return Properties.Resources.CheckPassPermission; }
        }

        public override string InvalidText
        {
            get { return Properties.Resources.CheckFailPermission; }
        }

        public override void Validate()
        {
            Log.WriteLog(Log.LogType.Info, "Start Permission Check...");
            try
            {
                if (SPFarm.Local.CurrentUserIsAdministrator())
                    this.Validated = true;
                else
                    this.Validated = false;
            }
            catch (Exception mm)
            {
                Log.WriteLog(Log.LogType.Info, "Permission Error:"+mm.ToString());
                this.Validated = false;
            }
        }
    }
}
